#coding=utf8
import subprocess,traceback,re
import sys,logging,logging.handlers,time
import lc_libs


if __name__ == "__main__":

	comd="snmpwalk -v 2c -c public 172.31.112.254 1.3.6.1.2.1.1"
	popen=subprocess.Popen(comd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
	line=popen.stdout.read()
	
	flag=0
	tempstr=""
	basiclist={}
	for lines in line.split('\n'):
		lines=lines.replace('\r','').replace('\n',' ')
		if "=" in lines:
			flag += 1
			tempstr = lines.split('=')[1]
			if ": " in tempstr:
				tempstr=tempstr.split(": ")[1].strip()
			basiclist[flag]=tempstr
		else:
			tempstr = tempstr + " " + lines
			basiclist[flag]=tempstr

	#系统描述
	sysDescr=basiclist[1]
	#ObjectID
	sysObjectID=basiclist[2]
	#系统启动时间(字符串)
	sysUpTimeInstance=basiclist[3]
	#系统启动时间(微秒)
	sysUpTimeSeconds=""
	res=re.findall(r"\((.*)\)",sysUpTimeInstance,re.S)
	if len(res) <> 0:
		sysUpTimeSeconds=res[0].strip()
	#联系人
	sysContact=basiclist[4]
	#设备名称
	sysName=basiclist[5]
	#地区
	sysLocation=basiclist[6]
	#服务
	sysServices=basiclist[7]
	#补丁更新时间
	sysORLastChange=basiclist[8]



	print '''		sysDescr : %s
		sysObjectID : %s
		sysUpTimeInstance : %s
		sysUpTimeSeconds : %s
		sysContact : %s
		sysName : %s
		sysLocation : %s
		sysServices : %s
		sysORLastChange : %s
	''' % (
		sysDescr,
		sysObjectID,
		sysUpTimeInstance,
		sysUpTimeSeconds,
		sysContact,
		sysName,
		sysLocation,
		sysServices,
		sysORLastChange
	)
